package com.gaga.metadata.common.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * StringQueryType
 **/
public enum StringQueryType {

    IN("in", "包含", "in"),
    OR("or", "或", "or"),
    EQ("eq", "等于", "="),
    NEQ("neq", "不等于", "!="),
    LIKE("like", "包含", "LIKE"),
    NLIKE("nlike", "不包含", "NOT LIKE"),
    LEFTLIKE("leftLike", "左包含", "LIKE"),
    RIGHTLIKE("rightLike", "右包含", "LIKE"),
    GT("gt", "大于", ">"),
    GTE("gte", "大于等于", ">="),
    LT("lt", "小于", "<="),
    LTE("lte", "小于等于", "<="),
    BTW("btw", "两者之间", "btw");

    private String code;
    private String desc;
    private String sqlCode;

    StringQueryType(String code, String desc, String sqlCode) {
        this.code = code;
        this.desc = desc;
        this.sqlCode = sqlCode;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public String getSqlCode() {
        return sqlCode;
    }

    public static StringQueryType ofCode(String oprCode) {
        for (StringQueryType dbOperatorType : values()) {
            if (dbOperatorType.code.equalsIgnoreCase(oprCode)) {
                return dbOperatorType;
            }
        }
        return null;
    }

    public String changeValueByType(String value) {
        switch (this) {
            case LIKE:
                return "%" + value + "%";
            case LEFTLIKE:
                return "%" + value;
            case RIGHTLIKE:
                return value + "%";
            default:
                return value;
        }
    }

    public static List<String> getCodeList() {
        List<String> codeList = new ArrayList<>();
        for (StringQueryType dbOperatorType : values()) {
            codeList.add(dbOperatorType.code);
        }
        return codeList;
    }

}
